﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace Tomahawk.Runtime.Timeline
{
    public class QuaternionTrack : BaseTrack
    {
        [XmlElement("X")]
        public string x = "";

        [XmlElement("Y")]
        public string y = "";

        [XmlElement("Z")]
        public string z = "";

        [XmlElement("W")]
        public string w = "";

        private Curve curveX = new Curve();
        private Curve curveY = new Curve();
        private Curve curveZ = new Curve();
        private Curve curveW = new Curve();

        public QuaternionTrack() { }

        public QuaternionTrack(string name) : base(name) { }

        protected override bool OnLoad(GraphicsDevice graphics, ContentManager contentManager)
        {
            curveX = LoadCurve(contentManager, x);
            curveY = LoadCurve(contentManager, y);
            curveZ = LoadCurve(contentManager, z);
            curveW = LoadCurve(contentManager, w);
            
            return base.OnLoad(graphics, contentManager);
        }

        public override void SortKeys() { }

        public override bool Update(float time)
        {
            if (curveX == null || curveY == null || curveZ == null || curveW == null)
            {
                return false;
            }

            Quaternion value = new Quaternion();
            value.X = curveX.Evaluate(time);
            value.Y = curveX.Evaluate(time);
            value.Z = curveX.Evaluate(time);
            value.W = curveX.Evaluate(time);

            return SetPropertyValue<Quaternion>(value);
        }
    }
}
